package ycj.learn.redis.service;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import ycj.learn.redis.model.User;

import java.util.List;

@Service
public class ContactServiceImpl implements IContactService {

    @Autowired
    RedisTemplate redisTemplate;


    @Override
    public User fetchOne(Long id) {
        String json = String.valueOf(redisTemplate.opsForValue().get(String.valueOf(id)));

        return JSON.parseObject(json, User.class);
    }

    @Override
    public boolean delOne(Long id) {
        return false;
    }

    @Override
    public boolean addOne(User user) {


        redisTemplate.opsForValue().set(String.valueOf(user.getId()),JSON.toJSONString(user));

        return true;
    }

    @Override
    public List<User> listAll() {
        return null;
    }
}
